
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript"
	src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBXjLdTmaYkzOIa-uIHnlWCCEm2MCCiMPg&sensor=true">
</script>
<script>
	var peternakanIconBase = '<?= base_url().'img/misc/'; ?>';
	function initialize(jenisTP){
		var mapProp = {
			center: new google.maps.LatLng(-7.28755, 112.733),
			zoom: 8,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById("ch-TP"), mapProp);
		allMaps.push(map);			
		<?php
			//var_dump($peternakan->result_array());
			if($titik_pasok != null){
				foreach($titik_pasok as $titik){
					$icon;
					if($titik["JENIS"] == "1"){
						$icon = "peternakan.png";
					}
					if($titik["JENIS"] == "2"){
						$icon = "rph.png";
					}
					if($titik["JENIS"] == "3"){
						$icon = "titik_penjualan.png";
					}
					if($titik["JENIS"] == "4"){
						$icon = "agen_sapi.png";
					}
					echo "
						if(jenisTP!=0){
							if(".$titik["JENIS"]."==jenisTP){
								var marker".$titik['ID_TITIK']." = new google.maps.Marker();
								marker".$titik['ID_TITIK'].".setPosition(new google.maps.LatLng(".$titik['LAT'].", ".$titik['LON']."));
								marker".$titik['ID_TITIK'].".setMap(map);
								
								marker".$titik['ID_TITIK'].".setIcon(peternakanIconBase + '".$icon."');
									
								var content".$titik['ID_TITIK']." = 'Nama: ".$titik['NAMA']." <br>Alamat: ".$titik['ALAMAT']."';
								var infoWindow".$titik['ID_TITIK']." = new google.maps.InfoWindow({content: content".$titik['ID_TITIK']."});
									
								onSpotClicked(marker".$titik['ID_TITIK'].", content".$titik['ID_TITIK'].", infoWindow".$titik['ID_TITIK'].", map);
									
								allMarkers[".$titik['ID_TITIK']."] = marker".$titik['ID_TITIK'].";
							}
						} else {
							var marker".$titik['ID_TITIK']." = new google.maps.Marker();
							marker".$titik['ID_TITIK'].".setPosition(new google.maps.LatLng(".$titik['LAT'].", ".$titik['LON']."));
							marker".$titik['ID_TITIK'].".setMap(map);
							
							marker".$titik['ID_TITIK'].".setIcon(peternakanIconBase + '".$icon."');
								
							var content".$titik['ID_TITIK']." = 'Nama: ".$titik['NAMA']." <br>Alamat: ".$titik['ALAMAT']."';
							var infoWindow".$titik['ID_TITIK']." = new google.maps.InfoWindow({content: content".$titik['ID_TITIK']."});
								
							onSpotClicked(marker".$titik['ID_TITIK'].", content".$titik['ID_TITIK'].", infoWindow".$titik['ID_TITIK'].", map);
								
							allMarkers[".$titik['ID_TITIK']."] = marker".$titik['ID_TITIK'].";
						}
					";
					
				}
			}		
		?>				
	}
	function onSpotClicked(marker, content, infowindow, map){
		google.maps.event.addListener(marker, "mouseover", function () {
			infowindow.setContent(content);
			infowindow.open(map,this);
		});		
		google.maps.event.addListener(marker, "mouseout", function () {
			infowindow.close();
		});
	}
	var allMarkers = [];

				
	function placeMarker(position, map) {
		var marker = new google.maps.Marker({
			position: position,
			map: map
		});
		map.panTo(position);
		marker.setIcon(peternakanIconBase + 'peternakan.png');
		markers.push(marker);
		map.setCenter(marker.getPosition());
	}
	
	var markers = [];
	var allMaps = [];
	function drawGmaps(jenisTP){
		google.maps.event.addDomListener(window, 'load', initialize(jenisTP));
	}
	
</script>